﻿Imports ATS.UI.Process
Imports ATS.Business.Entities
Imports System.ComponentModel
Imports System.ServiceModel
Imports System.Collections.Specialized
Imports System.Threading
Imports System.Collections.ObjectModel


Partial Public Class AssetWindow

    Private WithEvents _backgroundWorker As BackgroundWorker
    Private WithEvents _backgroundWorker_Page_Load As BackgroundWorker
    Private WithEvents _backgroundWorker_Save As BackgroundWorker
    Private WithEvents _backgroundWorker_CheckExisting As BackgroundWorker
    Public WithEvents oWindowList As OpenedWindowList = OpenedWindowList.GetList()
    Private WithEvents oWindow As OpenedWindowClass
    Private _upc As SubmitterUserProcess = Nothing
    Private _AssetDetail As MainAssetsTable = Nothing
    Private _AssetDisposedDetail As DisposedAsset = Nothing
    Private _AssetDetail_asynch As MainAssetsTable = Nothing
    Public WithEvents _AssetList As ObservableCollection(Of MainAssetsTable)
    Private _categoryList As List(Of Category) = Nothing
    Private _locationList As List(Of Location) = Nothing
    Private _departmentList As List(Of Department) = Nothing
    Private _personList As List(Of Person) = Nothing
    Private _disposalMethotList As List(Of String) = Nothing
    Private _windowIsDirty As Boolean = False


#Region "Window Events"
    Private Sub AssetWindow_Closed(sender As Object, e As System.EventArgs) Handles Me.Closed
        Dim ied As IEnumerable(Of OpenedWindowClass) = From d In oWindowList Where d.WindowID = Me.Name
        oWindowList.Remove(ied.First)
        If Application.Current.Windows.Count = 1 Then
            Application.Current.Windows(0).Activate()
        End If
    End Sub
    Private Sub AssetWindow_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles Me.Closing
        If Not _AssetDetail Is Nothing Then
            If _windowIsDirty Then
                If _
                    MessageBox.Show("There are unsaved entries. Do you really want to exit?", "Exit", _
                                     MessageBoxButton.YesNo, MessageBoxImage.Warning) = MessageBoxResult.No Then
                    e.Cancel = True
                    EndEdit()
                End If
            End If
        End If
    End Sub

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        _upc = New SubmitterUserProcess()
        _AssetDisposedDetail = New DisposedAsset
    End Sub

    Private Sub AssetWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        MaxHeight = System.Windows.SystemParameters.PrimaryScreenHeight
        mainOverlay.Visibility = Windows.Visibility.Visible
        _backgroundWorker_Page_Load = New BackgroundWorker
        _backgroundWorker_Page_Load.RunWorkerAsync()
    End Sub
#End Region

#Region "Control Events"
    Private Sub listBoxAssets_SelectionChanged(sender As Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles listBoxItems.SelectionChanged
        If Not _AssetDetail Is Nothing Then
            If _windowIsDirty Then
                If _
                    MessageBox.Show("Save entries before leaving?", "Save Data", MessageBoxButton.YesNo, _
                                     MessageBoxImage.Warning) = MessageBoxResult.Yes Then
                    SaveAsset()
                Else
                    If Not _AssetDetail.Assetno = "" Then
                        CancelEdit()
                    End If
                End If
                'clear validation
                EntryValidation.ValidateText(textboxDescription, True)
                EntryValidation.ValidateCombo(comboboxCategory, True)
            End If
        End If
        LoadSelectedAsset()
    End Sub

    Private Sub ExpanderList_Expanded(sender As Object, e As System.Windows.RoutedEventArgs) Handles ExpanderList.Expanded
        busyAnimation.Visibility = Windows.Visibility.Visible
        If _AssetList Is Nothing Then
            _backgroundWorker = New BackgroundWorker
            _backgroundWorker.RunWorkerAsync()
        Else
            busyAnimation.Visibility = Windows.Visibility.Collapsed
        End If
    End Sub

    Private Sub searchBox_GotFocus(sender As Object, e As RoutedEventArgs) Handles searchBox.GotFocus
        If searchBox.Text.ToUpper.Contains("SEARCH") Then
            searchBox.Text = Nothing
        End If
    End Sub

    Private Sub searchBox_TextChanged(sender As Object, e As TextChangedEventArgs) Handles searchBox.TextChanged
        If Not listBoxItems Is Nothing Then
            Dim icview As ICollectionView = CollectionViewSource.GetDefaultView(listBoxItems.ItemsSource)
            icview.Filter = New Predicate(Of Object)(AddressOf FilterUserTable)
        End If
    End Sub

    Private Sub buttonNew_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles buttonNew.Click
        'ExpanderList.IsExpanded = True
        If Not _AssetDetail Is Nothing Then
            If _windowIsDirty Then
                If _
                    MessageBox.Show("There are unsaved entries. Do you want to abandon your changes?", "Refresh", _
                                     MessageBoxButton.YesNo, MessageBoxImage.Warning) = MessageBoxResult.Yes Then
                    ResetDirtyBit()
                    SetWindowProperties(_windowIsDirty)
                    NewItemCanvas.Visibility = Windows.Visibility.Visible
                    ucNewItem.ucLabel = "New Asset Number"
                    'clear validation
                    EntryValidation.ValidateText(textboxDescription, True)
                    EntryValidation.ValidateCombo(comboboxCategory, True)
                End If
            Else
                NewItemCanvas.Visibility = Windows.Visibility.Visible
                ucNewItem.ucLabel = "New Asset Number"
            End If
        Else
            NewItemCanvas.Visibility = Windows.Visibility.Visible
            ucNewItem.ucLabel = "New Asset Number"
        End If
    End Sub

    Private Sub buttonRefresh_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles buttonRefresh.Click
        If Not _AssetDetail Is Nothing Then
            If _windowIsDirty Then
                If MessageBox.Show("There are unsaved entries. Do you really want to refresh the data?", "Refresh", _
                                     MessageBoxButton.YesNo, MessageBoxImage.Warning) = MessageBoxResult.Yes Then
                    If _AssetDetail.Assetno = "" Then
                        ClearAllControls(AssetWindow)
                        Me.Title = "Asset"
                        ResetDirtyBit()
                        SetWindowProperties(_windowIsDirty)
                    Else
                        CancelEdit()
                    End If
                    'clear validation
                    EntryValidation.ValidateText(textboxDescription, True)
                    EntryValidation.ValidateCombo(comboboxCategory, True)
                End If
            End If
        End If
    End Sub

    Private Sub buttonSave_Click(sender As Object, e As RoutedEventArgs) Handles buttonSave.Click
        If Not _AssetDetail Is Nothing Then
            If _windowIsDirty Then
                SaveAsset()
            End If
        End If
    End Sub

    Private Sub checkBoxDisposedAsset_Checked(sender As Object, e As System.Windows.RoutedEventArgs) Handles checkBoxDisposedAsset.Checked
        'If _AssetDetail.DisposedAsset Is Nothing Then
        '    _AssetDetail.DisposedAsset = New DisposedAsset

        'End If
        _windowIsDirty = True
        SetWindowProperties(_windowIsDirty)
    End Sub

    Private Sub checkBoxDisposedAsset_unChecked(sender As Object, e As System.Windows.RoutedEventArgs) Handles checkBoxDisposedAsset.Unchecked
        'If Not _AssetDetail.DisposedAsset Is Nothing Then
        '    _AssetDetail.DisposedAsset.MarkAsDeleted()

        'End If
        _windowIsDirty = True
        SetWindowProperties(_windowIsDirty)
    End Sub


#End Region

#Region "Background Workers"
    ' This event handler is where the actual work is done.
    Private Sub _backgroundWorker_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles _backgroundWorker.DoWork
        Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
        LoadAssets()
        LoadCategories()
        LoadLocations()
        LoadDepartments()
        LoadPersons()
    End Sub

    Private Sub _backgroundWorker_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles _backgroundWorker.RunWorkerCompleted
        If (e.Error IsNot Nothing) Then
            MessageBox.Show(e.Error.Message)
        Else
            listBoxItems.ItemsSource = _AssetList


            comboboxCategory.ItemsSource = _categoryList
            comboboxCategory.DisplayMemberPath = "CategoryName"
            comboboxCategory.SelectedValuePath = "CategoryCode"
            comboboxLocation.ItemsSource = _locationList
            comboboxLocation.DisplayMemberPath = "LocationName"
            comboboxLocation.SelectedValuePath = "LocationCode"
            comboboxDepartment.ItemsSource = _departmentList
            comboboxDepartment.DisplayMemberPath = "DepartmentName"
            comboboxDepartment.SelectedValuePath = "DepartmentCode"

            comboboxPerson.ItemsSource = _personList
            'comboboxPerson.DisplayMemberPath = "DepartmentName"
            comboboxPerson.SelectedValuePath = "EmployeeID"
            RefreshRecordCount()
            If _AssetList Is Nothing Then
                listBoxItems.SelectedIndex = -1
            End If

            comboboxDisposalType.ItemsSource = _disposalMethotList
            comboboxDisposalType.SelectedIndex = 0
            comboboxDisposalType.SelectedValuePath = "DisposalMethod"
            comboboxDisposalType.DisplayMemberPath = "DisposalMethod"
        End If
        busyAnimation.Visibility = Windows.Visibility.Collapsed
    End Sub

    Private Sub _backgroundWorker_SaveDoWork( _
                                          ByVal sender As Object, _
                                          ByVal e As DoWorkEventArgs) _
        Handles _backgroundWorker_Save.DoWork
        Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)

        If e.Argument = "edit" Then

            _AssetDetail_asynch = _upc.UpdateAssetDetails(_AssetDetail)
        ElseIf e.Argument = "new" Then
            _AssetDetail_asynch = _upc.CreateAsset(_AssetDetail)
        End If
    End Sub

    Private Sub _backgroundWorker_SaveRunWorkerCompleted( _
                                                      ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) _
        Handles _backgroundWorker_Save.RunWorkerCompleted
        If (e.Error IsNot Nothing) Then
            MessageBox.Show(e.Error.Message)
        Else
            listBoxItems.ItemsSource = _AssetList
            busyAnimationSaveAndDelete.Visibility = Windows.Visibility.Collapsed
            _AssetDetail = _AssetDetail_asynch
            _AssetDetail_asynch = Nothing
            ResetDirtyBit()
            SetWindowProperties(_windowIsDirty)
        End If
    End Sub

    ' This event handler is where the actual work is done.
    Private Sub _backgroundWorker_Page_Load_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles _backgroundWorker_Page_Load.DoWork
        Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
        LoadCategories()
        LoadLocations()
        LoadDepartments()
        LoadPersons()
        LoadDisposalType()
    End Sub

    Private Sub _backgroundWorker_Page_Load_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles _backgroundWorker_Page_Load.RunWorkerCompleted
        If (e.Error IsNot Nothing) Then
            MessageBox.Show(e.Error.Message)
        Else
            comboboxCategory.ItemsSource = _categoryList
            comboboxCategory.DisplayMemberPath = "CategoryName"
            comboboxCategory.SelectedValuePath = "CategoryCode"
            comboboxLocation.ItemsSource = _locationList
            comboboxLocation.DisplayMemberPath = "LocationName"
            comboboxLocation.SelectedValuePath = "LocationCode"
            comboboxDepartment.ItemsSource = _departmentList
            comboboxDepartment.DisplayMemberPath = "DepartmentName"
            comboboxDepartment.SelectedValuePath = "DepartmentCode"

            comboboxPerson.ItemsSource = _personList
            comboboxPerson.SelectedValuePath = "EmployeeID"
            RefreshRecordCount()

            comboboxDisposalType.ItemsSource = _disposalMethotList
            comboboxDisposalType.SelectedIndex = 0
            comboboxDisposalType.SelectedValuePath = "DisposalMethod"
            comboboxDisposalType.DisplayMemberPath = "DisposalMethod"
        End If
    End Sub

    Private Sub _backgroundWorker_ChckExistingUserDoWork( _
                                         ByVal sender As Object, _
                                         ByVal e As DoWorkEventArgs) _
       Handles _backgroundWorker_CheckExisting.DoWork
        Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
        e.Result = _upc.GetAssetDetails(e.Argument)
    End Sub

    Private Sub _backgroundWorker_ChckExistingRunWorkerCompleted( _
                                                      ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) _
        Handles _backgroundWorker_CheckExisting.RunWorkerCompleted
        If (e.Error IsNot Nothing) Then
            MessageBox.Show(e.Error.Message)
        Else
            If Not e.Result Is Nothing Then
                ucNewItem.LabelError.Content = "Asset code already exist."
            Else
                listBoxItems.SelectedIndex = -1
                _AssetDetail = New MainAssetsTable()
                HookupChangeEventHandler(_AssetDetail)
                Me.DataContext = _AssetDetail
                _AssetDetail.Assetno = ucNewItem.TextBoxNewUser.Text
                _windowIsDirty = _AssetDetail.IsDirty
                textboxAssetNumber.Text = ucNewItem.TextBoxNewUser.Text
                NewItemCanvas.Visibility = Windows.Visibility.Collapsed
                mainOverlay.Visibility = Visibility.Collapsed
                Me.Title = _AssetDetail.Assetno
                SetWindowProperties(_windowIsDirty)

            End If
        End If
        ucNewItem.busyAnimationNewUser_visibility = Windows.Visibility.Collapsed
    End Sub
#End Region

#Region "Support Procedures"
    Private Sub SaveAsset()
        busyAnimationSaveAndDelete.Visibility = Windows.Visibility.Visible
        Try
            'check for requiredfields
            If EntryValidation.ValidateText(textboxDescription, False) = False Or EntryValidation.ValidateCombo(comboboxCategory, False) = False Then
                Throw New Exception("Missing required fields. Please correct entry and try again.")
            End If


            _backgroundWorker_Save = New BackgroundWorker
            Dim AssetExist As Boolean = False

            If Not _AssetList Is Nothing Then
                If _AssetList.Where(Function(x) x.Assetno = textboxAssetNumber.Text).Count > 0 Then
                    AssetExist = True
                End If
            End If

            'diposal details
            ProcessDisposedAssetDetails()

            If AssetExist Then
                'edit
                _AssetDetail.LastModifiedBy = Environment.UserName
                _backgroundWorker_Save.RunWorkerAsync("edit")
                ResetDirtyBit()
            Else
                'new

                _AssetDetail = New MainAssetsTable
                With _AssetDetail
                    .DescriptiveName = textboxDescription.Text
                    .CategoryCode = comboboxCategory.SelectedValue
                    .LocationCode = comboboxLocation.SelectedValue
                    .DeptCode = comboboxDepartment.SelectedValue
                    .Section = textboxSection.Text
                    .AssignToEmployeeCode = comboboxPerson.SelectedValue
                    .SalvageValue = textboxSalvageValue.Text
                    .ReplacementCost = textboxReplacementCost.Text
                    .Condition = textboxCondition.Text
                    .Status = textboxStatus.Text
                    .SerialNumber = textboxSerialNumber.Text
                    .Assetno = textboxAssetNumber.Text
                    .RFIDno = textboxRFIDNumber.Text
                    .InvoiceNumber = textboxInvoiceNumber.Text
                    .DateAcquired = textboxPurchasedDate.SelectedDate
                    .BoughtFrom = textboxBoughtFrom.Text
                    .BaseCost = textboxBaseCost.Text
                    .VAT = textboxVAT.Text
                    .Manufacturer = textboxManufacturer.Text
                    .BrandName = textboxBrand.Text
                    .ModelNumber = textboxModelNumber.Text
                    .Remarks = textboxRemarks.Text
                    .LastModifiedBy = Environment.UserName
                    .Createdby = Environment.UserName
                    .DisposedAsset = _AssetDisposedDetail
                End With



                _backgroundWorker_Save.RunWorkerAsync("new")

                If Not _AssetList Is Nothing Then
                    'update list
                    _AssetList.Add(_AssetDetail)
                    sortData()
                    Dim ctr As Integer = 0
                    For Each item In _AssetList
                        If item.Assetno = _AssetDetail.Assetno Then
                            Exit For
                        End If
                        ctr += 1
                    Next
                    listBoxItems.SelectedIndex = ctr
                End If
            End If
            ResetDirtyBit()
            SetWindowProperties(_windowIsDirty)

            _backgroundWorker_Save.Dispose()
        Catch faultEx As FaultException
            MessageBox.Show(faultEx.Message, "Error Saving Asset Details", MessageBoxButton.OK, MessageBoxImage.[Error])
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error Saving Asset Details", MessageBoxButton.OK, MessageBoxImage.[Error])
        End Try
        busyAnimationSaveAndDelete.Visibility = Windows.Visibility.Collapsed
    End Sub

    Private Sub SetWindowProperties(dirty As Boolean)
        If dirty Then
            Me.Title &= If(Not Me.Title.ToUpper.Contains("UNSAVED"), " (unsaved)", "")
        Else
            Me.Title = If(Title.ToUpper.Contains("UNSAVED"), Me.Title.Substring(0, Me.Title.Length - 10), Me.Title)
        End If

        For itemIndex = 0 To oWindowList.Count - 1
            If oWindowList(itemIndex).WindowID = Me.Name Then
                oWindowList(itemIndex).WindowName = Me.Title
                oWindowList(itemIndex).WindowIsDirty = dirty
            End If
        Next
    End Sub

    Private Sub LoadSelectedAsset()
        If listBoxItems.SelectedIndex >= 0 Then
            _AssetDetail = listBoxItems.SelectedItem

            Me.DataContext = _AssetDetail
            If _AssetDetail.DisposedAsset Is Nothing Then
                checkBoxDisposedAsset.IsChecked = False
            Else
                checkBoxDisposedAsset.IsChecked = True
            End If
            _AssetDisposedDetail = _AssetDetail.DisposedAsset()
            HookupChangeEventHandler(_AssetDetail)

            mainOverlay.Visibility = Visibility.Collapsed
            Me.Title = textboxAssetNumber.Text
            BeginEdit()
            ResetDirtyBit()
            SetWindowProperties(_windowIsDirty)
        Else
            _AssetDetail = Nothing
            Me.Title = "Asset"
            mainOverlay.Visibility = Visibility.Visible
        End If
        If _AssetDetail Is Nothing Then
            _windowIsDirty = False
        End If
        SetWindowProperties(_windowIsDirty)
    End Sub

    Private Sub HookupChangeEventHandler(AssetDetail As MainAssetsTable)
        ' Add a PropertyChanged event handler for 
        ' the specified Customer instance:
        AddHandler _AssetDetail.PropertyChanged, _
            AddressOf HandlePropertyChanged

        If Not _AssetDetail.DisposedAsset Is Nothing Then
            AddHandler _AssetDetail.DisposedAsset.PropertyChanged, _
            AddressOf HandlePropertyChanged
        End If

    End Sub

    Private Sub HandlePropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
        If _AssetDetail.IsDirty Then
            _windowIsDirty = _AssetDetail.IsDirty
            SetWindowProperties(_AssetDetail.IsDirty)
        End If
        If Not _AssetDisposedDetail Is Nothing Then
            If _AssetDisposedDetail.IsDirty Then
                _windowIsDirty = _AssetDisposedDetail.IsDirty
                SetWindowProperties(_AssetDisposedDetail.IsDirty)
            End If
        End If
    End Sub

    Public Function FilterUserTable(ByVal t As Object) As Boolean
        Dim _assets As MainAssetsTable
        _assets = t
        Return _assets.Assetno.ToUpper.Contains(searchBox.Text.ToUpper)
    End Function

    Sub ClearAllControls(controlName As Control)
        HelperClass.ClearCheckBox(controlName)
        HelperClass.ClearComboBox(controlName)
        HelperClass.ClearPasswordBox(controlName)
        HelperClass.ClearTextBox(controlName)
    End Sub

    Private Sub LoadAssets()
        Try
            If _AssetList Is Nothing Then
                _AssetList = New ObservableCollection(Of MainAssetsTable)(_upc.GetAllAssets)

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message & ControlChars.Lf & ex.ToString, "Error loading Asset list", MessageBoxButton.OK, _
                             MessageBoxImage.[Error])
        End Try
    End Sub

    Private Sub RefreshRecordCount()
        If Not _AssetList Is Nothing Then
            If _AssetList.Count = 1 Then
                ExpanderText.Text = _AssetList.Count & " record found"
            Else
                ExpanderText.Text = _AssetList.Count & " records found"
            End If
        End If
    End Sub

    Private Sub TextBox_Error(sender As Object, e As ValidationErrorEventArgs)
        If e.Action = ValidationErrorEventAction.Added Then
            DirectCast(sender, Control).ToolTip = e.[Error].ErrorContent.ToString()
        Else
            DirectCast(sender, Control).ToolTip = ""
        End If
    End Sub

    Sub sortData()
        Dim ied As IEnumerable(Of MainAssetsTable) = From d In _AssetList Order By d.DescriptiveName
        For Each i In ied
            _AssetList.Remove(i)
            _AssetList.Add(i)
        Next
    End Sub

    Private Sub ProcessDisposedAssetDetails()
        'check for disposed details
        If checkBoxDisposedAsset.IsChecked Then
            _AssetDisposedDetail = New DisposedAsset
            _AssetDisposedDetail.Assetno = _AssetDetail.Assetno
            _AssetDisposedDetail.DateSold = textboxDateDisposed.SelectedDate
            _AssetDisposedDetail.AmountSold = textboxAmountSold.Text
            _AssetDisposedDetail.Profit = textboxProfit.Text
            _AssetDisposedDetail.DisposalGainLoss = textboxGainLoss.Text
            _AssetDisposedDetail.DisposalAccmDepr = textboxAccumulatedDepreciation.Text
            _AssetDisposedDetail.DisposalBV = textboxBV.Text
            _AssetDisposedDetail.DisposalMethod = comboboxDisposalType.Text
            _AssetDetail.DisposedAsset = _AssetDisposedDetail
        ElseIf Not checkBoxDisposedAsset.IsChecked Then 'delete
            _AssetDetail.DisposedAsset = Nothing
        Else 'edit
            _AssetDetail.DisposedAsset = _AssetDisposedDetail
        End If
    End Sub

    Private Sub ResetDirtyBit()
        _AssetDetail.ResetDirtyBit()
        If Not _AssetDetail.DisposedAsset Is Nothing Then
            _AssetDetail.DisposedAsset.ResetDirtyBit()
        End If
        _windowIsDirty = False
    End Sub

    Private Sub BeginEdit()
        _AssetDetail.BeginEdit()
        'If Not _AssetDetail.DisposedAsset Is Nothing Then
        '    _AssetDetail.DisposedAsset.BeginEdit()
        'End If
    End Sub

    Private Sub CancelEdit()
        _AssetDetail.CancelEdit()
        'If Not _AssetDetail.DisposedAsset Is Nothing Then
        '    _AssetDetail.DisposedAsset.CancelEdit()
        'End If
        ResetDirtyBit()
        SetWindowProperties(_windowIsDirty)
    End Sub

    Private Sub EndEdit()
        _AssetDetail.EndEdit()
        If Not _AssetDetail.DisposedAsset Is Nothing Then
            _AssetDetail.DisposedAsset.EndEdit()
        End If
    End Sub
#End Region

#Region "Load Defaults"
    Private Sub LoadCategories()
        _categoryList = _upc.ReadAllCategories
    End Sub

    Private Sub LoadLocations()
        _locationList = _upc.ReadAllLocations
    End Sub

    Private Sub LoadDepartments()
        _departmentList = _upc.GetAllDepartments
    End Sub
    Private Sub LoadPersons()
        _personList = _upc.GetAllPersons
    End Sub

    Private Sub LoadDisposalType()
        _disposalMethotList = _upc.GetDisposalMethods
    End Sub
#End Region

#Region "User Control Events"

    Private Sub uc_OKButtonClicked(ByVal sender As Object, ByVal e As RoutedEventArgs) _
        Handles ucNewItem.OkButtonClicked
        ucNewItem.busyAnimationNewUser_visibility = Windows.Visibility.Visible
        _backgroundWorker_CheckExisting = New BackgroundWorker
        _backgroundWorker_CheckExisting.RunWorkerAsync(ucNewItem.TextBoxNewUser.Text)
        _backgroundWorker_CheckExisting.Dispose()
    End Sub

    Private Sub uc_CancelButtonClicked(ByVal sender As Object, ByVal e As RoutedEventArgs) _
        Handles ucNewItem.CancelButtonClicked
        NewItemCanvas.Visibility = Windows.Visibility.Collapsed
    End Sub

#End Region
End Class



